import React, { useState, useEffect } from 'react';
import { GetItem } from '../../util/util';
import './scss/time.scss';

const time = () => {
  useEffect(() => {
    window.time = setInterval(() => {
      if (isRandom) {
        setTimeId(GetItem());
      }
    }, 1000);
    return () => {
      clearInterval(window.time);
      setIsRandom(false);
    };
  }, []);
  const [isRandom, setIsRandom] = useState(true);
  const [timeId, setTimeId] = useState(GetItem());
  return <div className="HomeTime">{timeId}</div>;
};

export default time;
